import requests
import json
from bs4 import BeautifulSoup
import urllib.request
import os.path
# response = requests.get("http://www.baidu.com/")
#print (response.text)
# 也可以这么写
# response = requests.request("get", "http://www.baidu.com/")

 
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36","X-Gaia-Api-Key":"99c74f76-698d-4028-8bc3-8ae950762ee2","Content-Type":"application/json" }
 
# params 接收一个字典或者字符串的查询参数，字典类型自动转换为url编码，不需要urlencode()
response = requests.get("https://m.dytt8.net/index2.htm", headers = headers)
 
# 查看响应内容，response.text 返回的是Unicode格式的数据
#print (response.text)
#print (response.text)
response.encoding='GB2312'
html = response.text
#print(html)
# soup = BeautifulSoup(html,'html.parser',fromEncoding="gb18030")
soup = BeautifulSoup(html,'html.parser',fromEncoding="gb2312")
#获取所有的img标签
movie = soup.find_all('img')
alink = soup.findAll('a')
#获取src路径
path ="https://m.dytt8.net"
# for i in movie:
#     imgsrc = i.get('src')   
#     print(path+imgsrc)
# python 获取文件路径中的文件名
urllib.request.urlretrieve('https://bingo.longhu.net/file/downloadasync?fileId=12fcb5a3-70c5-4dad-b0fe-44f8ad6250f2' , "D:\\img\\12fcb5a3-70c5-4dad-b0fe-44f8ad6250f2")
    #print (i.get('src'))
# def GetRequestImgs(url):
#     rr = requests.get(url, headers = headers,timeout=1)
#     #设置response 编码类型 防止 中文乱码
#     rr.encoding='GB2312'
#     imgs = soup.findAll('img')
#     return imgs
# for a in alink:
#     src = a.get('href')
#     #print(a.text)
#     try:
#         imgs = GetRequestImgs(src)
#     except:
#         print ("error")
#     for img in imgs:
#         print(a.text+img.get('src'))